package com.hnyfkj.jyindustry.biz.weather.controller;

import com.hnyfkj.jyindustry.biz.weather.dto.WeatherReportListDto;
import com.hnyfkj.jyindustry.biz.weather.entity.WeatherReportList;
import com.hnyfkj.jyindustry.biz.weather.service.WeatherReportListService;
import com.hnyfkj.jyindustry.common.dto.PageReturnDto;
import com.hnyfkj.jyindustry.common.dto.RespDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/weather")
@Api(tags = { "天气" })
public class WeatherReportListController {
	
	@Autowired
	private WeatherReportListService weatherReportListService;


	/**
	 * 完善页面
	 */
	@GetMapping("/listPage")
	public String improve() {
		return "weather/weather-table";
	}


	/**
	 * 添加页面
	 */
	@GetMapping("/look")
	public String look(@RequestParam("id") String id, Model model) {
		WeatherReportList weatherReportList = weatherReportListService.getById(id);
		model.addAttribute("weatherReportList", weatherReportList);
		return "weather/weather-detail";
	}


	/**
	 * 列表
	 *
	 * @param weatherReportListDto
	 * @return
	 */
	@PostMapping("/list")
	@ResponseBody
	@ApiOperation(value = "列表", produces = "application/json")
	public RespDto<PageReturnDto<WeatherReportList>> selectListDto(@RequestBody final WeatherReportListDto weatherReportListDto) {
		return RespDto.succResult(weatherReportListService.selectListDto(weatherReportListDto));
	}


	/**
	 * 删除
	 *
	 * @param id
	 * @return
	 */
	@DeleteMapping("/delete")
	@ResponseBody
	@ApiOperation(value = "删除", produces = "application/x-www-form-urlencoded")
	public RespDto<String> delete(final String id) {
		weatherReportListService.removeById(id);
		return RespDto.succ("删除成功");
	}

	/**
	 * 删除(批量)
	 *
	 * @param id
	 * @return
	 */
	@DeleteMapping("/deleteByIds")
	@ResponseBody
	@ApiOperation(value = "删除", produces = "application/x-www-form-urlencoded")
	public RespDto<String> deleteByIds(final String id) {
		return weatherReportListService.deleteByIds(id);
	}


}
